/**
 * 初始化部门详情对话框
 */
var UpdateInfoDlg = {
    CustomerInfoData: {},
    zTreeInstance: null,
    validateFields: {}
};

/**
 * 清除数据
 */
UpdateInfoDlg.clearData = function () {
    this.customerInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
UpdateInfoDlg.set = function (key, val) {
    this.customerInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
UpdateInfoDlg.get = function (key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
UpdateInfoDlg.close = function () {
    // parent.layer.close(window.parent.Customer.layerIndex);
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}


/**
 * 显示部门选择的树
 *
 * @returns
 */
UpdateInfoDlg.showCustomerSelectTree = function () {
    var pName = $("#pName");
    var pNameOffset = $("#pName").offset();
    $("#parentCustomerMenu").css({
        left: pNameOffset.left + "px",
        top: pNameOffset.top + pName.outerHeight() + "px"
    }).slideDown("fast");

    $("body").bind("mousedown", onBodyDown);
}

/**
 * 隐藏部门选择的树
 */
UpdateInfoDlg.hideCustomerSelectTree = function () {
    $("#parentCustomerMenu").fadeOut("fast");
    $("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发，不用弹起
}

/**
 * 收集数据
 */
UpdateInfoDlg.collectData = function () {
    this.set('id').set('oneChannel').set('twoChannel').set('thrChannel').set('sOneChannel').set('sTwoChannel').set('sThrChannel').set('archiving').set('remarks').set('name');
}


/**
 * 验证数据是否为空
 */
UpdateInfoDlg.validate = function () {
    $('#updateInfoForm').data("bootstrapValidator").resetForm();
    $('#updateInfoForm').bootstrapValidator('validate');
    return $("#updateInfoForm").data('bootstrapValidator').isValid();
}


//修改渠道
UpdateInfoDlg.updateChannel = function () {
    var id= $("#ids").val();
    var index = layer.open({
        type: 2,
        title: '修改渠道',
        area: ['60%', '50%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/cusupdate_channel/'+id
    });
    this.layerIndex = index;
};


/**
 * 渠道修改提交
 */
UpdateInfoDlg.updateSubmit = function () {
    var name = $("#name").val();                   //建档人
    var sOneChannel = $("#sOneChannel").val();     //原一级渠道
    var sTwoChannel = $("#sTwoChannel").val();     //原二级渠道
    var sThrChannel = $("#sThrChannel").val();     //原三级渠道
    var archiving = $("#archiving").val();         //提交人
    var oneChannel = $("#oneChannel").val();       //一级渠道
    var twoChannel = $("#twoChannel").val();       //二级渠道
    var thrChannel = $("#thrChannel").val();       //三级渠道
    var remarks = $("#remarks").val();             //备注
    var reservationsId = $("#reservationsId").val();
    var customerId = $("#customerId").val();
    if(remarks == "" || remarks == null){
        alert("请输入备注！");
        return;
    }
    $.ajax({
        url: Feng.ctxPath + "/customer/update_channel1",
        type: "post",
        data: {
            name:name,sOneChannel:sOneChannel,sTwoChannel:sTwoChannel,sThrChannel:sThrChannel,reservationsId:reservationsId,
            archiving:archiving,oneChannel:oneChannel,twoChannel:twoChannel,thrChannel:thrChannel,remarks:remarks,customerId:customerId
        },
        success: function (data) {
            Feng.success('操作成功!');
            UpdateInfoDlg.close();
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
};


